#!/bin/bash

./remake.sh

echo "Parsing"
../parser $1.cmm > $1.i1
if [ $? -ne 0 ]; then echo 'Failed'; exit; fi

echo "Optimizing"
python ../optimizer.py < $1.i1 > $1.i
if [ $? -ne 0 ]; then echo 'Failed'; exit; fi

echo "Producing Assembly"
python ../assembler.py < $1.i > $1.s
if [ $? -ne 0 ]; then echo 'Failed'; exit; fi

echo "Running"
echo "-"
if [ -e $1.in ]
then
	spim -file $1.s -quiet < $1.in | tail --lines=+6 #> $1.p
else
	spim -file $1.s -quiet | tail --lines=+6 #> $1.p
fi
#cat $1.p
echo
